/**
 * (created at 2011-1-21)
 */
package qiushuo.mysqlparser.ast.expression.primary;

import qiushuo.mysqlparser.ast.expression.Expression;
import qiushuo.mysqlparser.generator.SQLType;

/**
 * <code>'EXISTS' '(' subquery ')'</code>
 * 
 * @author <a href="mailto:QiuShuo1985@gmail.com">QIU Shuo</a>
 */
public class ExistsPrimary extends PrimaryExpression {
    private final Expression subquery;

    public ExistsPrimary(Expression subquery) {
        this.subquery = subquery;
    }

    @Override
    public String generateSql(SQLType type) {
        switch (type) {
        case MySQL:
            StringBuilder sb = new StringBuilder();
            sb.append("EXISTS ").append(subquery.generateSql(type));
            return sb.toString();
        default:
            throw new UnsupportedOperationException("only mysql sql can be generated");
        }
    }
}
